package com.right.health.app.ui.me;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.magic.basic.activity.BaseActivity;
import com.right.health.app.R;
import com.right.health.app.app.App;
import com.right.health.app.hyphenate.EMClientHelper;
import com.right.health.app.push.TagAliasOperatorHelper;
import com.right.health.app.ui.common.ArticleDetailActivity;
import com.right.health.app.ui.main.MainActivity;
import com.right.health.app.ui.user.ForgetPwdStep1Activity;
import com.right.health.app.ui.user.ForgetPwdStep2Activity;
import com.right.health.app.ui.user.LoginActivity;

import essclib.esscpermission.setting.Setting;

import static com.right.health.app.push.TagAliasOperatorHelper.ACTION_DELETE;

/*
 * Created by hopeliao on 2019-09-29
 * 设置
 *
 */
public class SettingsActivity extends BaseActivity implements View.OnClickListener {

    @Override
    public void onCreate(Bundle bundle, String s) {
        setContentView(R.layout.settings);
    }

    @Override
    public void findView() {
        findViewById(R.id.rl_modify_pwd).setOnClickListener(this);
        findViewById(R.id.item_user_protocol).setOnClickListener(this);
        findViewById(R.id.tv_exit_login).setOnClickListener(this);
    }

    @Override
    public void initialize() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_modify_pwd:
                ForgetPwdStep2Activity.launch(this,"修改密码");
                break;
            case R.id.item_user_protocol:
                ArticleDetailActivity.makeActivity(this, "用户协议", "https://doctor.yb-aliyun.com/pandWx/agreement/h5_provisions_declare.html");
                break;
            case R.id.tv_exit_login:
                new AlertDialog.Builder(this).setMessage("确认是否退出登录??")
                        .setPositiveButton("退出", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                App.getInstance().refreshUser(null);
                                EMClientHelper.getInstance().logout();
                                Intent intent = new Intent(SettingsActivity.this, LoginActivity.class);
                                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                TagAliasOperatorHelper.sequence++;
                                TagAliasOperatorHelper.TagAliasBean delBean = new TagAliasOperatorHelper.TagAliasBean();
                                delBean.action = ACTION_DELETE;
                                delBean.isAliasAction = true;
                                TagAliasOperatorHelper.getInstance().handleAction(SettingsActivity.this,  TagAliasOperatorHelper.sequence, delBean);
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog1, int which) {
                        dialog1.dismiss();
                    }
                }).create().show();
                break;
        }
    }


}
